﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DirectSell.Model.Manager;
using System.Collections;
using Direct.IDAL.Manager.ServiceCenter;

namespace DirectSell.BLL.Manager.ServiceCenter
{
    /// <summary>
    /// 服务中心审核服务层
    /// </summary>
    public class SerciceCenterAuditService:ManagerService
    {
        #region 日志记录
        /// <summary>
        /// 日志记录文件名
        /// </summary>
        protected override string LogFile
        {
            get
            {
                return "服务中心审核";
            }
        }
        #endregion

        #region 构造函数
        /// <summary>
        /// 服务中心审核服务层
        /// </summary>
        protected IServiceCenterAuditRepository _repository { get; set; }

        public SerciceCenterAuditService(IServiceCenterAuditRepository repository)
        {
            this._repository = repository;
        }

        #endregion

        #region 操作入口
        /// <summary>
        /// 操作入口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="param"></param>
        /// <returns></returns>
        protected async override Task<ManagerRespCode> OperationAsync<T>(T param)
        {
            var model = param as ServiceCenterAuditReq;

            if (model == null)
            {
                return ManagerRespCode.失败;
            }

            await LogAsync(model);

            Hashtable hstable = new Hashtable();

            _repository.Audit(model.UserCode, model.Type,ref hstable);

            if (model.Type == 0)
            {
                _repository.DelectRecord(model.UserCode,ref hstable);
            }

            if (!_repository.CommitDapperTranLock(hstable))
            {
                return ManagerRespCode.失败;
            }

            return ManagerRespCode.成功;

        }
        #endregion
    }
}
